//
//  SoundChangeViewController.m
//  LazyCat
//
//  Created by jike on 15/12/16.
//  Copyright (c) 2015年 zhanshu. All rights reserved.
//

#import "SoundChangeViewController.h"

@interface SoundChangeViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    UITableView *_tableView;
    NSString *lingsheng;
    NSString *zhendong;
}

@end

@implementation SoundChangeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initNav:@"消息提醒" doBack:YES];
    UIView *lineView = [[UIView alloc]init];
    lineView.frame = CGRectMake(0, 63, ScreenWidth, 1);
    lineView.backgroundColor = [UIColor lightGrayColor];
    lineView.alpha = 0.2;
    [self.navBar addSubview:lineView];
    [self createTable];
}

-(void)createTable {
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, ScreenWidth, 110) style:UITableViewStyleGrouped];
    _tableView.rowHeight = 50;
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.scrollEnabled = NO;
    [self.view addSubview:_tableView];
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 10;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(10, 15, 150, 20)];
    [cell addSubview:lab];
    [AppData share].doFirst = NO;
    [NSUserDefualManager storageValue:[NSNumber numberWithBool:YES] forKey:@"DoFirstLogin"];
    lingsheng = [NSUserDefualManager getValueByKey:@"lingsheng"];
    zhendong = [NSUserDefualManager getValueByKey:@"zhendong"];
    NSLog(@"%@+++++++%@",lingsheng,zhendong);
    
    if (indexPath.row == 0) {
        lab.text = @"铃声提醒";
        UISwitch *switchView1 = [[UISwitch alloc] initWithFrame:CGRectMake(ScreenWidth - 70, 10, 60, 25)];
        if ([lingsheng isEqualToString:@"1"]) {
            
            switchView1.on = YES;//设置初始关闭
        }else {
            
            switchView1.on = NO;
        }
        
        [switchView1 addTarget:self action:@selector(oneAction:) forControlEvents:UIControlEventValueChanged];
        [cell addSubview:switchView1];
        //设置ON一边的背景颜色，默认是绿色
        switchView1.onTintColor=  MainColor;
    }else{
        lab.text = @"震动提醒";
        UISwitch *switchView2 = [[UISwitch alloc] initWithFrame:CGRectMake(ScreenWidth - 70, 10, 60, 25)];
        if ([zhendong isEqualToString:@"1"]) {
            switchView2.on = YES;//设置初始关闭
        }else {
            switchView2.on = NO;
        }
        [switchView2 addTarget:self action:@selector(twoAction:) forControlEvents:UIControlEventValueChanged];
        switchView2.onTintColor=  MainColor;
        [cell addSubview:switchView2];
    }
    lab.font = [UIFont systemFontOfSize:15];
    return cell;
}
-(void)oneAction:(UISwitch *)swich {
    if (swich.isOn) {  // 铃声
        [NSUserDefualManager storageValue:@"1" forKey:@"lingsheng"];
        NSLog(@"one开");
    }else{
        [NSUserDefualManager storageValue:@"0" forKey:@"lingsheng"];
        NSLog(@"one关");
    }
}
-(void)twoAction:(UISwitch *)swich {
    if (swich.isOn) { // 震动
        [NSUserDefualManager storageValue:@"1" forKey:@"zhendong"];
        NSLog(@"two开");
    }else{
        [NSUserDefualManager storageValue:@"0" forKey:@"zhendong"];
        NSLog(@"two关");
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
@end
